<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
      <el-form-item label="收货人名称" prop="shouhuoren">
        <el-input v-model="queryParams.shouhuoren" placeholder="请输入收货人名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="收货人电话" prop="shouhuotel">
        <el-input v-model="queryParams.shouhuotel" placeholder="请输入收货人电话" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['develop:GoodsShouhuoren:add']">新增</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>


    <el-table border v-loading="loading"  :data="dataList" @selection-change="handleSelectionChange" ref="table"
      :max-height="tableMaxHeight">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="收货人姓名" align="center" prop="shouhuoren"  />
      <el-table-column label="收货人电话" align="center" prop="shouhuotel"  />
      <el-table-column label="业务经理及电话" align="center" prop="jingli" show-overflow-tooltip  />
      <el-table-column label="客户姓名" align="center" prop="customName" show-overflow-tooltip  />
      <el-table-column label="收货地址" align="center" prop="address" show-overflow-tooltip  />
      <el-table-column label="备注" align="center" prop="remark" show-overflow-tooltip />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['develop:GoodsShouhuoren:edit']">修改</el-button>
          <el-popconfirm :title="`确认删除当前数据项？`" @confirm="handleDelete(scope.row)" style="margin-left: 10px;">
            <el-button slot="reference" size="mini" type="text" icon="el-icon-delete"
              v-hasPermi="['develop:GoodsShouhuoren:remove']">删除</el-button>
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <goodsShouhuoren-form ref="form" @ok="getList"></goodsShouhuoren-form>
  </div>
</template>

<script>
  import {
    deleteAction,
    getAction
  } from '@/api/manage'
  import GoodsShouhuorenForm from '@/views/develop/goodsShouhuoren/module/GoodsShouhuorenForm'

  export default {
    name: "GoodsShouhuorenList",
    components: {
      GoodsShouhuorenForm,
    },
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 收货人表格数据
        dataList: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          code: null,
          shouhuoren: null,
          shouhuotel: null,
          address: null,
          customId: null,
          customName: null
        },
        url: {
          list: '/goodsShouhuoren/goodsShouhuoren/list',
          remove: '/goodsShouhuoren/goodsShouhuoren/',
          export: '/goodsShouhuoren/goodsShouhuoren/export',
        },
        tableMaxHeight: window.innerHeight - 320,
      };
    },
    created() {
      this.getList();
      window.addEventListener('resize', this.getTableHeight);
    },
    destroyed() {
      window.removeEventListener('resize', this.getTableHeight)
    },
    methods: {
      /** 查询收货人列表 */
      getList() {
        this.loading = true;
        getAction(this.url.list, this.queryParams).then(response => {
          this.dataList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      getTableHeight() {
        this.tableHeight = window.innerHeight - 320
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.$refs.form.handleAdd();
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.$refs.form.handleUpdate(row);
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        deleteAction(this.url.remove, ids).then(response => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download(this.url.export, {
          ...this.queryParams
        }, `goodsShouhuoren_${new Date().getTime()}.xlsx`)
      },
    }
  };
</script>
